<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>完整demo</title>
	<link rel="stylesheet" href="../layui/css/layui.css">
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <script type="text/javascript" charset="utf-8" src="ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="ueditor.all.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>
	<script src="../layui/layui.js"></script>
		
    <style type="text/css">
        div{
            width:100%;
        }
    </style>
</head>
<body>
<div>
	<form class="layui-form" action="">
	  <div class="layui-form-item">
	    <label class="layui-form-label">单行输入框</label>
	    <div class="layui-input-block">
	      <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">验证必填项</label>
	    <div class="layui-input-block">
	      <input type="text" name="username" lay-verify="required" lay-reqtext="用户名是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">验证手机</label>
	      <div class="layui-input-inline">
	        <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input">
	      </div>
	    </div>
	    <div class="layui-inline">
	      <label class="layui-form-label">验证邮箱</label>
	      <div class="layui-input-inline">
	        <input type="text" name="email" lay-verify="email" autocomplete="off" class="layui-input">
	      </div>
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">多规则验证</label>
	      <div class="layui-input-inline">
	        <input type="text" name="number" lay-verify="required|number" autocomplete="off" class="layui-input">
	      </div>
	    </div>
	    <div class="layui-inline">
	      <label class="layui-form-label">验证日期</label>
	      <div class="layui-input-inline">
	        <input type="text" name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
	      </div>
	    </div>
	    <div class="layui-inline">
	      <label class="layui-form-label">验证链接</label>
	      <div class="layui-input-inline">
	        <input type="tel" name="url" lay-verify="url" autocomplete="off" class="layui-input">
	      </div>
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">验证身份证</label>
	    <div class="layui-input-block">
	      <input type="text" name="identity" lay-verify="identity" placeholder="" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">自定义验证</label>
	    <div class="layui-input-inline">
	      <input type="password" name="password" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
	    </div>
	    <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
	  </div>
	  
	  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">范围</label>
	      <div class="layui-input-inline" style="width: 100px;">
	        <input type="text" name="price_min" placeholder="￥" autocomplete="off" class="layui-input">
	      </div>
	      <div class="layui-form-mid">-</div>
	      <div class="layui-input-inline" style="width: 100px;">
	        <input type="text" name="price_max" placeholder="￥" autocomplete="off" class="layui-input">
	      </div>
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">单行选择框</label>
	    <div class="layui-input-block">
	      <select name="interest" lay-filter="aihao">
	        <option value=""></option>
	        <option value="0">写作</option>
	        <option value="1" selected="">阅读</option>
	        <option value="2">游戏</option>
	        <option value="3">音乐</option>
	        <option value="4">旅行</option>
	      </select>
	    </div>
	  </div>
	  
	  
	  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">分组选择框</label>
	      <div class="layui-input-inline">
	        <select name="quiz">
	          <option value="">请选择问题</option>
	          <optgroup label="城市记忆">
	            <option value="你工作的第一个城市">你工作的第一个城市</option>
	          </optgroup>
	          <optgroup label="学生时代">
	            <option value="你的工号">你的工号</option>
	            <option value="你最喜欢的老师">你最喜欢的老师</option>
	          </optgroup>
	        </select>
	      </div>
	    </div>
	    <div class="layui-inline">
	      <label class="layui-form-label">搜索选择框</label>
	      <div class="layui-input-inline">
	        <select name="modules" lay-verify="required" lay-search="">
	          <option value="">直接选择或搜索选择</option>
	          <option value="1">layer</option>
	          <option value="2">form</option>
	          <option value="3">layim</option>
	          <option value="4">element</option>
	          <option value="5">laytpl</option>
	          <option value="6">upload</option>
	          <option value="7">laydate</option>
	          <option value="8">laypage</option>
	          <option value="9">flow</option>
	          <option value="10">util</option>
	          <option value="11">code</option>
	          <option value="12">tree</option>
	          <option value="13">layedit</option>
	          <option value="14">nav</option>
	          <option value="15">tab</option>
	          <option value="16">table</option>
	          <option value="17">select</option>
	          <option value="18">checkbox</option>
	          <option value="19">switch</option>
	          <option value="20">radio</option>
	        </select>
	      </div>
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">联动选择框</label>
	    <div class="layui-input-inline">
	      <select name="quiz1">
	        <option value="">请选择省</option>
	        <option value="浙江" selected="">浙江省</option>
	        <option value="你的工号">江西省</option>
	        <option value="你最喜欢的老师">福建省</option>
	      </select>
	    </div>
	    <div class="layui-input-inline">
	      <select name="quiz2">
	        <option value="">请选择市</option>
	        <option value="杭州">杭州</option>
	        <option value="宁波" disabled="">宁波</option>
	        <option value="温州">温州</option>
	        <option value="温州">台州</option>
	        <option value="温州">绍兴</option>
	      </select>
	    </div>
	    <div class="layui-input-inline">
	      <select name="quiz3">
	        <option value="">请选择县/区</option>
	        <option value="西湖区">西湖区</option>
	        <option value="余杭区">余杭区</option>
	        <option value="拱墅区">临安市</option>
	      </select>
	    </div>
	    <div class="layui-form-mid layui-word-aux">此处只是演示联动排版，并未做联动交互</div>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">复选框</label>
	    <div class="layui-input-block">
    <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
	    </div>
	  </div>
	  






	</form>

</div>
<div id="btns">
    <div>
        <button onclick="getAllHtml()">获得整个html的内容</button>
        <button onclick="getContent()">获得内容</button>
        <button onclick="setContent()">写入内容</button>
        <button onclick="setContent(true)">追加内容</button>
        <button onclick="getContentTxt()">获得纯文本</button>
        <button onclick="getPlainTxt()">获得带格式的纯文本</button>
        <button onclick="hasContent()">判断是否有内容</button>
        <button onclick="setFocus()">使编辑器获得焦点</button>
        <button onmousedown="isFocus(event)">编辑器是否获得焦点</button>
        <button onmousedown="setblur(event)" >编辑器失去焦点</button>

    </div>
    <div>
        <button onclick="getText()">获得当前选中的文本</button>
        <button onclick="insertHtml()">插入给定的内容</button>
        <button id="enable" onclick="setEnabled()">可以编辑</button>
        <button onclick="setDisabled()">不可编辑</button>
        <button onclick=" UE.getEditor('editor').setHide()">隐藏编辑器</button>
        <button onclick=" UE.getEditor('editor').setShow()">显示编辑器</button>
        <button onclick=" UE.getEditor('editor').setHeight(300)">设置高度为300默认关闭了自动长高</button>
    </div>

    <div>
        <button onclick="getLocalData()" >获取草稿箱内容</button>
        <button onclick="clearLocalData()" >清空草稿箱</button>
    </div>

</div>
<div>
    <button onclick="createEditor()">
    创建编辑器</button>
    <button onclick="deleteEditor()">
    删除编辑器</button>
</div>

<script type="text/javascript">
	layui.use(['form', 'layedit', 'laydate'], function(){
	  var form = layui.form
	  ,layer = layui.layer
	  ,layedit = layui.layedit
	  ,laydate = layui.laydate;
		
		
		//实例化编辑器
		//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
		var ue = UE.getEditor('editor',{
			UEDITOR_HOME_URL:"../ueditor/",
			serverUrl:"http://127.0.0.1:8080/ue/edit"
		});
		console.log(ue)
		
		function isFocus(e){
		    alert(UE.getEditor('editor').isFocus());
		    UE.dom.domUtils.preventDefault(e)
		}
		function setblur(e){
		    UE.getEditor('editor').blur();
		    UE.dom.domUtils.preventDefault(e)
		}
		function insertHtml() {
		    var value = prompt('插入html代码', '');
		    UE.getEditor('editor').execCommand('insertHtml', value)
		}
		function createEditor() {
		    enableBtn();
		    UE.getEditor('editor');
		}
		function getAllHtml() {
		    alert(UE.getEditor('editor').getAllHtml())
		}
		function getContent() {
		    var arr = [];
		    arr.push("使用editor.getContent()方法可以获得编辑器的内容");
		    arr.push("内容为：");
		    arr.push(UE.getEditor('editor').getContent());
		    alert(arr.join("\n"));
		}
		function getPlainTxt() {
		    var arr = [];
		    arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
		    arr.push("内容为：");
		    arr.push(UE.getEditor('editor').getPlainTxt());
		    alert(arr.join('\n'))
		}
		function setContent(isAppendTo) {
		    var arr = [];
		    arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
		    UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
		    alert(arr.join("\n"));
		}
		function setDisabled() {
		    UE.getEditor('editor').setDisabled('fullscreen');
		    disableBtn("enable");
		}
		
		function setEnabled() {
		    UE.getEditor('editor').setEnabled();
		    enableBtn();
		}
		
		function getText() {
		    //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
		    var range = UE.getEditor('editor').selection.getRange();
		    range.select();
		    var txt = UE.getEditor('editor').selection.getText();
		    alert(txt)
		}
		
		function getContentTxt() {
		    var arr = [];
		    arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
		    arr.push("编辑器的纯文本内容为：");
		    arr.push(UE.getEditor('editor').getContentTxt());
		    alert(arr.join("\n"));
		}
		function hasContent() {
		    var arr = [];
		    arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
		    arr.push("判断结果为：");
		    arr.push(UE.getEditor('editor').hasContents());
		    alert(arr.join("\n"));
		}
		function setFocus() {
		    UE.getEditor('editor').focus();
		}
		function deleteEditor() {
		    disableBtn();
		    UE.getEditor('editor').destroy();
		}
		function disableBtn(str) {
		    var div = document.getElementById('btns');
		    var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
		    for (var i = 0, btn; btn = btns[i++];) {
		        if (btn.id == str) {
		            UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
		        } else {
		            btn.setAttribute("disabled", "true");
		        }
		    }
		}
		function enableBtn() {
		    var div = document.getElementById('btns');
		    var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
		    for (var i = 0, btn; btn = btns[i++];) {
		        UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
		    }
		}
		
		function getLocalData () {
		    alert(UE.getEditor('editor').execCommand( "getlocaldata" ));
		}
		
		function clearLocalData () {
		    UE.getEditor('editor').execCommand( "clearlocaldata" );
		    alert("已清空草稿箱")
		}
	})
 
</script>
</body>
</html>